<?php
// +----------------------------------------------------------------------
// | motto: 不懈努力，只为遇见更好的自己
// +----------------------------------------------------------------------
// | Copyright: (c) 2020 http://www.slong.ink All rights reserved.
// +----------------------------------------------------------------------
// | Licensed: http://www.apache.org/licenses/LICENSE-2.0
// +----------------------------------------------------------------------
// | Author: slongzhang <slongzhang@qq.com>
// +----------------------------------------------------------------------
// | Date: 2023/9/29
// +----------------------------------------------------------------------
// | Time: 21:06
// +----------------------------------------------------------------------

// 获取根目录
function getRootPath() {
    return __DIR__;
}

// 获取应用目录
function getAppPath() {
    return __DIR__ . DIRECTORY_SEPARATOR . 'app';
}

// 获取配置目录
function getConfigPath() {
    return __DIR__ . DIRECTORY_SEPARATOR . 'config';
}

// ajaxJson输出
function ajax_json($code = 0, $msg = 'ok', $data = array()) {
    if (is_array($code)) {
        $result = $code;
    }
    else {
        $result = array(
            'code'  => $code,
            'msg'   => $msg,
        );
        if (!empty($data)) {
            $result['data'] = $data;
        }
    }
    return json_encode($result, 320);
}

/**
 * 校验json字符串
 * @param string $stringData
 * @return bool
 */
function is_json_str($stringData)
{
    if (empty($stringData)) return false;

    try
    {
        //校验json格式
        json_decode($stringData, true);
        return JSON_ERROR_NONE === json_last_error();
    }
    catch (\Exception $e)
    {
        return false;
    }
}

// 返回毫秒时间戳
function msectime() {
    list($msec, $sec) = explode(' ', microtime());
    return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
}

// 获取guzzle请求实例
function http_client($options = null, $name = null) {
    return \Extend\facade\HttpClient::facadeGetClient($options, $name);
}